#!/usr/bin/python3
# -*- coding: utf-8 -*-
"""
@author:  runyuanye
@contact: runyuanye@163.com
"""

import argparse
import os
import sys
import random
import shutil

sys.path.append('.')

"""
   转换为只有文件名的列表
"""


def read_file_list(file_list):
    files = []
    file_count = 0
    with open(file_list, 'r') as file:
        for line in file.readlines():
            file_count += 1
            if file_count % 10000 == 0:
                print('Read File Count: {}'.format(file_count))

            # if file_count == 10000:
            #     break

            # 015ff272-3768-4d4c-bebc-c14dc93065cd 477fc604-1479-4745-b8e9-9440a6ac8187 f8e4735b44724e25077106e0eaef15f0.jpg 0
            lines = line.strip().split()

            # faceid = lines[0]
            # subfaceid = lines[1]
            file_name = lines[2]

            files.append(file_name)

        print('Read File Count: {}'.format(file_count))
    return files


def main():
    parser = argparse.ArgumentParser(description="To Face Image FileName List")
    parser.add_argument(
        "--file_list", default="/rootfs/media/kasim/Data1/data/VideoFaceImage/filter8/FilterSelectFace.txt", help="path to image file list", type=str
    )
    parser.add_argument(
        "--output_dir", default="/rootfs/media/kasim/Data1/data/VideoFaceImage/filter8", help="path to output", type=str
    )
    args = parser.parse_args()

    output_dir = args.output_dir
    if not os.path.exists(output_dir):
        os.makedirs(output_dir)
        os.system('chmod a+wr {}'.format(output_dir))

    files = read_file_list(args.file_list)

    out_file_path = os.path.join(output_dir, 'FaceImageFileNameList.txt')
    with open(out_file_path, 'w') as file:
        for file_name in files:
            file.write(file_name + '\n')

    os.system('chmod a+wr {}'.format(out_file_path))

    print('finish!')


if __name__ == '__main__':
    main()
